<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <style type="text/css">
        .el-main {
            position: absolute;
            top: 70px;
            bottom: 0px;
            left: 200px;
            right: 10px;
            padding: 0;
        }
    </style>

</head>
<body class="hold-transition skin-purple sidebar-mini">
<div id="app">
    <el-container>
        <el-header class="main-header" style="height:70px;">
            <nav class="navbar navbar-static-top" :class=''>
                <!-- Logo -->
                <a href="#" class="logo" style="text-align:center">
                    <span class="logo-lg"><img src="../img/logo.png"></span>
                </a>
                <div class="right-menu">
                    <span class="help"><i class="fa fa-exclamation-circle" aria-hidden="true"></i>帮助</span>
                    <el-dropdown @command="handleCommand" class="avatar-container right-menu-item" trigger="click">
                        <div class="avatar-wrapper">
                            <img src="../img/user2-160x160.jpg" class="user-avatar">
                            {{username}}
                        </div>
                        <el-dropdown-menu slot="dropdown">
                            <el-dropdown-item divided command="updatePwd">
                                <span style="display:block;">修改密码</span>
                            </el-dropdown-item>
                            <el-dropdown-item divided command="logout">
                                <span style="display:block;">退出</span>
                            </el-dropdown-item>
                        </el-dropdown-menu>
                    </el-dropdown>
                </div>
            </nav>
        </el-header>
        <el-container>
            <el-aside width="200px">
                <el-menu>
                    <el-submenu v-for="menu in menuList" :index="menu.path">
                        <template slot="title">
                            <i class="fa" :class="menu.icon"></i>
                            {{menu.name}}
                        </template>
                        <template v-for="child in menu.children">
                            <el-menu-item :index="child.path">
                                <a :href="child.linkUrl" target="right">{{child.name}}</a>
                            </el-menu-item>
                        </template>
                    </el-submenu>
                </el-menu>
            </el-aside>
            <el-container>
                <!--<iframe name="right" class="el-main" src="/pages/user.html" width="100%" height="100%"-->
                <iframe name="right" class="el-main" src="/pages/checkitem.html" width="100%" height="100%"
                        frameborder="0"></iframe>
            </el-container>
        </el-container>
    </el-container>
</div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script>
    new Vue({
        el: '#app',
        data: {
            username: '',
            menuList: []
        },
        methods: {
            handleCommand(commond) {
                if (commond == 'logout') {
                    window.location.href = "http://localhost:82/logout.do";
                }
            }
            ,
            /*权限认证的方法*/
            loadfunction() {
                axios.defaults.withCredentials = true;
                axios.get("http://localhost:82/user/findUsername.do").then((res) => {
                    //接受返回的数据，如果返回的数据为空则提示用户进行登录
                    console.log(res.data.data);
                    if (res.data.data) {
                        this.username = res.data.data;
                        //执行完权限认定后，获取永辉对应的菜单
                        this.loadMenuFun(this.username);
                    } else {
                        //弹出提示框
                        this.$alert(
                            '<a href="http://localhost:83/login.html">点击跳转登录</a>',
                            {
                                dangerouslyUseHTMLString: true,
                                center: true,
                                showClose: false,
                            }
                        ).then((res) => {
                            document.location.href = "http://localhost:83/login.html"
                        });
                    }
                }).catch((err) => {
                    console.log(err);
                });
            },
            //根据用户名查询用户所对应的菜单
            loadMenuFun(username) {
                axios.defaults.withCredentials = true;
                axios.get("http://localhost:82/menu/getmenu.do?username=" + username).then((res) => {
                    console.log(res.data.data);
                    this.menuList = res.data.data;
                    this.$message({
                        type: "success",
                        message: res.data.message
                    });
                }).catch((err) => {
                    console.log(err);
                });
            }
        },
        created() {
            this.loadfunction();
        }
    });
    $(function () {
        var wd = 200;
        $(".el-main").css('width', $('body').width() - wd + 'px');
    });
</script>
</html>
